package com.adong.service.impl;

import com.adong.dao.imlp.UserDaoImpl;
import com.adong.pojo.User;
import com.adong.service.UserService;

import java.sql.Connection;

/**
 * @author adong
 */
public class UserServiceImpl implements UserService {
    private UserDaoImpl userDaoImpl = new UserDaoImpl();

    /**
     * 注册到数据库
     *
     * @param user user对象
     * @return 成功返回操作的函数, 否者返回-1
     */

    @Override
    public int registerUser( User user) {
        return userDaoImpl.saveUser(user);

    }

    /**
     * 登录数据库
     *
     * @param user 登录的user
     * @return 成功放回对象, 失败返回null
     */
    @Override
    public User loginUser( User user) {
        System.out.println("userServiceImpl:"+user);
        return userDaoImpl.queryUserAndPassWord( user.getUsername(), user.getPassword());
    }

    /**
     * 查询用户名
     * @param userName 用户名
     * @return 存在用户名返回 true ,不存在用户名返回false
     */
    @Override
    public Boolean checkUserName(String userName) {
        if (userDaoImpl.queryUserName(userName) == null) {
            return false;
        }
        return true;
    }
}
